package com.sumi.erp.controller;

import com.sumi.common.annotation.Log;
import com.sumi.common.core.controller.BaseController;
import com.sumi.common.core.domain.AjaxResult;
import com.sumi.common.core.page.TableDataInfo;
import com.sumi.common.enums.BusinessType;
import com.sumi.common.utils.poi.ExcelUtil;
import com.sumi.erp.domain.BaseContractTemplate;
import com.sumi.erp.service.IBaseContractTemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 合同模版Controller
 * 
 * @author <hmy>fgf67@163.com
 * @date 2024-06-26
 */
@RestController
@RequestMapping("/erp/template")
public class BaseContractTemplateController extends BaseController
{
    @Autowired
    private IBaseContractTemplateService baseContractTemplateService;

    /**
     * 查询合同模版列表
     */
    @PreAuthorize("@ss.hasPermi('system:template:list')")
    @GetMapping("/list")
    public TableDataInfo list(BaseContractTemplate baseContractTemplate)
    {
        startPage();
        List<BaseContractTemplate> list = baseContractTemplateService.selectBaseContractTemplateList(baseContractTemplate);
        return getDataTable(list);
    }

    /**
     * 导出合同模版列表
     */
    @PreAuthorize("@ss.hasPermi('system:template:export')")
    @Log(title = "合同模版", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseContractTemplate baseContractTemplate)
    {
        List<BaseContractTemplate> list = baseContractTemplateService.selectBaseContractTemplateList(baseContractTemplate);
        ExcelUtil<BaseContractTemplate> util = new ExcelUtil<BaseContractTemplate>(BaseContractTemplate.class);
        util.exportExcel(response, list, "合同模版数据");
    }

    /**
     * 获取合同模版详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:template:query')")
    @GetMapping(value = "/{templateId}")
    public AjaxResult getInfo(@PathVariable("templateId") Long templateId)
    {
        return success(baseContractTemplateService.selectBaseContractTemplateByTemplateId(templateId));
    }

    /**
     * 新增合同模版
     */
    @PreAuthorize("@ss.hasPermi('system:template:add')")
    @Log(title = "合同模版", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseContractTemplate baseContractTemplate)
    {
        return toAjax(baseContractTemplateService.insertBaseContractTemplate(baseContractTemplate));
    }

    /**
     * 修改合同模版
     */
    @PreAuthorize("@ss.hasPermi('system:template:edit')")
    @Log(title = "合同模版", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseContractTemplate baseContractTemplate)
    {
        return toAjax(baseContractTemplateService.updateBaseContractTemplate(baseContractTemplate));
    }

    /**
     * 删除合同模版
     */
    @PreAuthorize("@ss.hasPermi('system:template:remove')")
    @Log(title = "合同模版", businessType = BusinessType.DELETE)
	@DeleteMapping("/{templateIds}")
    public AjaxResult remove(@PathVariable Long[] templateIds)
    {
        return toAjax(baseContractTemplateService.deleteBaseContractTemplateByTemplateIds(templateIds));
    }
}
